# frozen_string_literal: true

module Vulnerabilities
  class UpdateNamespaceIdsOfVulnerabilityReadsWorker
    include ApplicationWorker

    feature_category :vulnerability_management

    data_consistency :always # rubocop:disable SidekiqLoadBalancing/WorkerDataConsistency (This worker mainly updates data)
    worker_resource_boundary :unknown
    idempotent!

    def perform(project_id)
      UpdateNamespaceIdsOfVulnerabilityReadsService.execute(project_id)
    rescue Gitlab::ExclusiveLeaseHelpers::FailedToObtainLockError
      logger.info(
        class: self.class.name,
        message: "Couldn't obtain the lock. Rescheduling the job.",
        project_id: project_id)

      self.class.perform_in(2.minutes, project_id)
    end
  end
end
